WTL Controls
Back to the WTL Controls Home Page.
BIS_WTL_CONTROLS::CODComboBox Class Reference

An owner-drawn combo box featuring textual content with per-item colors and fonts. More...

#include <ODComboBox.h>

Inheritance diagram for BIS_WTL_CONTROLS::CODComboBox:

Public Member Functions

 CODComboBox () noexcept
 
virtual ~CODComboBox ()
 
void SubclassComboBox (HWND wnd)
 Subclass a combobox control. More...
 
void UnSubclassComboBox ()
 Un-subclass main and component windows; free GDI resources. More...
 
void SetAutoAdjustDropRectWidth (bool value)
 Change the AutoAdjustRectWidth state. More...
 
bool GetAutoAdjustDropRectWidth () const
 Default: true. More...
 
void SetMaxDropDownWidth (int value)
 Sets the upper limit to the width of the dropdown list, if it is being automatically adjusted. More...
 
int GetMaxDropDownWidth () const
 Default: 400 pixels. More...
 
void UpdateControlHeight ()
 Update the combobox height to accomodate all content. More...
 
void UpdateDropDownWidth ()
 Force an update of the width of the drop down list. More...
 
bool ODAddItem ()
 Add new item to the end of the list box. More...
 
bool ODAddItem (std::basic_string< TCHAR > text, COLORREF text_color, COLORREF back_color, HFONT font, int height, CHorzAlignment horz, CVertAlignment vert, bool wrap, bool use_ellipsis)
 Add a new item to the end of the list box, populated with specified data. More...
 
bool ODInsertItem (int index)
 Insert an item. More...
 
bool ODInsertItem (int index, std::basic_string< TCHAR > text, COLORREF text_color, COLORREF back_color, HFONT font, int height, CHorzAlignment horz, CVertAlignment vert, bool wrap, bool use_ellipsis)
 Insert a new item at the position indicated by index. More...
 
bool ODRemoveItem (int index)
 Deletes an item from the drop-down list. More...
 
void SetODItemText (int index, std::basic_string< TCHAR > text)
 Modify the text associated with a combobox item. More...
 
std::basic_string< TCHAR > GetODItemText (int index) const
 Default: "". More...
 
void SetODItemBackColor (int index, COLORREF color)
 Modify the background color of the selected combobox item. More...
 
COLORREF GetODItemBackColor (int index) const
 Default: COLOR_WINDOW. More...
 
void SetODItemTextColor (int index, COLORREF color)
 Modify the text color of the selected combobox item. More...
 
COLORREF GetODItemTextColor (int index) const
 Default: COLOR_WINDOWTEXT. More...
 
void SetODItemFont (int index, HFONT font)
 Modify the font assigned to the selected combobox item. More...
 
HFONT GetODItemFont (int index) const
 Default: The font assigned to the combo box when the CODComboItem object is instantiated. More...
 
void SetODItemHeight (int index, int height)
 Modify the height of the selected combobox item. More...
 
int GetODItemHeight (int index) const
 Default: The height of the control portion of the combobox at the time the CODComboItem is instantiated. More...
 
void SetODItemHorzAlignment (int index, CHorzAlignment value)
 Modify the horizontal text alignment of the selected combobox item. More...
 
CHorzAlignment GetODItemHorzAlignment (int index) const
 Default: haLeft. More...
 
void SetODItemVertAlignment (int index, CVertAlignment value)
 Modify the vertical text aligment of the selected combobox item. More...
 
CVertAlignment GetODItemVertAlignment (int index) const
 DefaultL: vaMiddle. More...
 
void SetODItemWordWrap (int index, bool wrap)
 Modify the WordWrap state of the selected combobox item. More...
 
bool GetODItemWordWrap (int index) const
 Default: false. More...
 
void SetODItemUseEllipsis (int index, bool ellipsis)
 Modify the UseEllipsis state of the selected combobox item. More...
 
bool GetODItemUseEllipsis (int index) const
 Default: true. More...
 

Detailed Description

An owner-drawn combo box featuring textual content with per-item colors and fonts.

IMPORTANT: This class only works properly with 'drop-list' combo boxes (i.e; those created with the CBS_DROPDOWNLIST style flag), not 'simple' comboboxes (those created with the CBS_SIMPLE style flag) or ' drop down' comboboxes (those created with the CBS_DROPDOWN flag). In addition, CBS_HASSTRINGS must be FALSE.

The owner-drawn style can be set to either fixed or variable (i.e., the combobox style can include either CBS_OWNERDRAW or CBS_OWNERDRAWVARIABLE). If variable owner-draw mode is selected, CBS_NOINTEGRALHEIGHT must also be included among the control's style flags.

CBS_SORT is supported; sorting will be based on the text content.

Finally, the dialog container must reflect all Owner Drawn messages (WM_DRAWITEM, WM_MEASUREITEM, WM_COMPAREITEM and WM_DELETEITEM) back to the control, either with the non-discriminating REFLECT_NOTIFICATIONS_EX, or with something more selective (e.g, REFLECT_NOTIFICATIONS_MSG_ID_FILETERED).

With the above caveats, usage is straight-forward.

CODComboBox odCombo1;
odCombo1.SubclassStatic(GetDlgItem(IDC_ODCOMBO1));
odCombo1.SetItemHeight(-1, 30);
odCombo1.ODAddItem(_T("string1"), CLR_GREEN, CLR_YELLOW, m_ArialFont.Handle(), 50, haCenter, vaMiddle, false, false);
odCombo1.ODAddItem(_T("string2jhgjh"), CLR_RED, CLR_WHITE, m_FunnyFont.Handle(), 60, haCenter, vaMiddle, true, true);
odCombo1.ODAddItem(_T("string3"), CLR_LAVENDER, CLR_ORANGE, m_ArialFont.Handle(), 30, haCenter, vaMiddle, false, false);
.
.
.
odCombo1.UnSubclassComboBox(); // when finished using the control (probably in OnEndDialog).

Definition at line 56 of file ODComboBox.h.

Constructor & Destructor Documentation

◆ CODComboBox()

BIS_WTL_CONTROLS::CODComboBox::CODComboBox ( )
noexcept

Definition at line 90 of file ODComboBox.cpp.

◆ ~CODComboBox()

BIS_WTL_CONTROLS::CODComboBox::~CODComboBox ( )
virtual

Definition at line 103 of file ODComboBox.cpp.

Member Function Documentation

◆ SubclassComboBox()

void BIS_WTL_CONTROLS::CODComboBox::SubclassComboBox ( HWND  hWnd)

Subclass a combobox control.

This also grabs the window handles of the list box and control portions of the combobox. Note that the control portion can be either a static text control or a edit control, depending on whether or not the contents of the combobox can be edited.

Parameters
hWndThe window handle of the control to subclass.
Return values
void

Definition at line 121 of file ODComboBox.cpp.

◆ UnSubclassComboBox()

void BIS_WTL_CONTROLS::CODComboBox::UnSubclassComboBox ( )

Un-subclass main and component windows; free GDI resources.

Definition at line 148 of file ODComboBox.cpp.

◆ SetAutoAdjustDropRectWidth()

void BIS_WTL_CONTROLS::CODComboBox::SetAutoAdjustDropRectWidth ( bool  value)

Change the AutoAdjustRectWidth state.

Parameters
valueNew bool state.
Return values
void

Definition at line 190 of file ODComboBox.cpp.

◆ GetAutoAdjustDropRectWidth()

bool BIS_WTL_CONTROLS::CODComboBox::GetAutoAdjustDropRectWidth ( ) const

Default: true.

If true, the drop box width is adjusted to accommodate the longest string in the list box. The width will not be less than the control width, and will not be greater than the max limit set through SetMaxDropDownWidth. if false, drop down width will be equal to the control width.

Return values
bool

Definition at line 175 of file ODComboBox.cpp.

◆ SetMaxDropDownWidth()

void BIS_WTL_CONTROLS::CODComboBox::SetMaxDropDownWidth ( int  value)

Sets the upper limit to the width of the dropdown list, if it is being automatically adjusted.

Parameters
valueNew maximum, in pixels.
Return values
void

Definition at line 219 of file ODComboBox.cpp.

◆ GetMaxDropDownWidth()

int BIS_WTL_CONTROLS::CODComboBox::GetMaxDropDownWidth ( ) const

Default: 400 pixels.

The maximum width allowed when AutoAdjustDropRectWidth is true.

Return values
int

Definition at line 205 of file ODComboBox.cpp.

◆ UpdateControlHeight()

void BIS_WTL_CONTROLS::CODComboBox::UpdateControlHeight ( )

Update the combobox height to accomodate all content.

The width of the combobox's footprint is left unchanged, but the height of the rectangle is recaulculated to allow for the current contents of the listbox. Useful afer adding or removing items from the list.

Return values
void

Definition at line 784 of file ODComboBox.cpp.

◆ UpdateDropDownWidth()

void BIS_WTL_CONTROLS::CODComboBox::UpdateDropDownWidth ( )

Force an update of the width of the drop down list.

If AutoAdjustWidth is true, the drop-down width will be set equal to the length of the longest string in the list box, within limits: if the length of the longest string is less than the width of the control portion of the combobox, the width will be set to the width of the control portion, and if the width of the longest string is greater than the MaxDropDownWidth value, the width will be set to MaxDropDownWidth.

If AutoAdjustWidth is /c true, the width of the dropdown list will be set equal to the width of the control portion of the combobox.

Return values
void

Definition at line 741 of file ODComboBox.cpp.

◆ ODAddItem() [1/2]

bool BIS_WTL_CONTROLS::CODComboBox::ODAddItem ( )

Add new item to the end of the list box.

The new item will be instantiated with default values; current control font will be assigned to new item, and item height will be set to control window (edit or static) height.

Return values
boolTrue is item is successfully added.

Definition at line 235 of file ODComboBox.cpp.

◆ ODAddItem() [2/2]

bool BIS_WTL_CONTROLS::CODComboBox::ODAddItem ( std::basic_string< TCHAR >  text,
COLORREF  text_color,
COLORREF  back_color,
HFONT  font,
int  height,
CHorzAlignment  horz,
CVertAlignment  vert,
bool  wrap,
bool  use_ellipsis 
)

Add a new item to the end of the list box, populated with specified data.

Parameters
text
text_color
back_color
font
height
horz
vert
wrap
use_ellipsis
Return values
boolTrue is item is successfully added.

Definition at line 270 of file ODComboBox.cpp.

◆ ODInsertItem() [1/2]

bool BIS_WTL_CONTROLS::CODComboBox::ODInsertItem ( int  index)

Insert an item.

The new item will be instantiated with default values; current control font will be assigned to new item, and item height will be set to control window (edit or static) height.

Parameters
indexThe zero-based index of the position at which to insert the new item. If this parameter is -1, the item is added to the end of the list.
Return values
boolTrue is item is successfully inserted.

Definition at line 311 of file ODComboBox.cpp.

◆ ODInsertItem() [2/2]

bool BIS_WTL_CONTROLS::CODComboBox::ODInsertItem ( int  index,
std::basic_string< TCHAR >  text,
COLORREF  text_color,
COLORREF  back_color,
HFONT  font,
int  height,
CHorzAlignment  horz,
CVertAlignment  vert,
bool  wrap,
bool  use_ellipsis 
)

Insert a new item at the position indicated by index.

Inserts a new object at the position indicated by the zero-based index parameter. If this parameter is -1, the item is added to the end of the list.

Parameters
index
text
text_color
back_color
font
height
horz
vert
wrap
use_ellipsis
Return values
boolTrue is item is successfully inserted.

Definition at line 348 of file ODComboBox.cpp.

◆ ODRemoveItem()

bool BIS_WTL_CONTROLS::CODComboBox::ODRemoveItem ( int  index)

Deletes an item from the drop-down list.

If the CB_HASSTRINGS flag is false (as it should be), calling DeleteString results in a WM_DELETEITEM message being sent; this is processed and the CODComboItem at the location indicated be index is deleted.

Parameters
index
Return values
boolTrue is item is successfully removed.

Definition at line 389 of file ODComboBox.cpp.

◆ SetODItemText()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemText ( int  index,
std::basic_string< TCHAR >  text 
)

Modify the text associated with a combobox item.

Parameters
indexThe zero-based index of the item to modify.
textNew text.
Return values
void

Definition at line 426 of file ODComboBox.cpp.

◆ GetODItemText()

std::basic_string< TCHAR > BIS_WTL_CONTROLS::CODComboBox::GetODItemText ( int  index) const

Default: "".

Returns the text associated with the indicated combobox item.

Parameters
indexZero-based item index.
Return values
std::basic_string<TCHAR>The selected item's current text.

Definition at line 407 of file ODComboBox.cpp.

◆ SetODItemBackColor()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemBackColor ( int  index,
COLORREF  color 
)

Modify the background color of the selected combobox item.

Parameters
indexThe zero-based index of the item to modify.
colorThe new background color.
Return values
void

Definition at line 464 of file ODComboBox.cpp.

◆ GetODItemBackColor()

COLORREF BIS_WTL_CONTROLS::CODComboBox::GetODItemBackColor ( int  index) const

Default: COLOR_WINDOW.

Returns the background color of the selected combobox item.

Parameters
indexZero-based item index.
Return values
COLORREFThe selected item's current background color.

Definition at line 445 of file ODComboBox.cpp.

◆ SetODItemTextColor()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemTextColor ( int  index,
COLORREF  color 
)

Modify the text color of the selected combobox item.

Parameters
indexThe zero-based index of the item to modify.
colorThe new text color.
Return values
void

Definition at line 501 of file ODComboBox.cpp.

◆ GetODItemTextColor()

COLORREF BIS_WTL_CONTROLS::CODComboBox::GetODItemTextColor ( int  index) const

Default: COLOR_WINDOWTEXT.

Returns the text color of the selected combobox item.

Parameters
indexZero-based item index.
Return values
COLORREFThe selected item's current text color.

Definition at line 482 of file ODComboBox.cpp.

◆ SetODItemFont()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemFont ( int  index,
HFONT  font 
)

Modify the font assigned to the selected combobox item.

Parameters
indexThe zero-based index of the item to modify.
fontThe handle to the new font.
Return values
void

Definition at line 537 of file ODComboBox.cpp.

◆ GetODItemFont()

HFONT BIS_WTL_CONTROLS::CODComboBox::GetODItemFont ( int  index) const

Default: The font assigned to the combo box when the CODComboItem object is instantiated.

Returns the handle of the selected item's font.

Parameters
indexZero-based item index.
Return values
HFONTThe handle of the selected item's font.

Definition at line 518 of file ODComboBox.cpp.

◆ SetODItemHeight()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemHeight ( int  index,
int  height 
)

Modify the height of the selected combobox item.

Parameters
indexThe zero-based index of the item to modify.
heightThe new height.
Return values
void

Definition at line 575 of file ODComboBox.cpp.

◆ GetODItemHeight()

int BIS_WTL_CONTROLS::CODComboBox::GetODItemHeight ( int  index) const

Default: The height of the control portion of the combobox at the time the CODComboItem is instantiated.

Returns the current height of the selected combobox item.

Parameters
indexZero-based item index.
Return values
intThe selected item's current height.

Definition at line 556 of file ODComboBox.cpp.

◆ SetODItemHorzAlignment()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemHorzAlignment ( int  index,
CHorzAlignment  value 
)

Modify the horizontal text alignment of the selected combobox item.

Parameters
indexThe zero-based index of the item to modify.
valueThe new horizontal alignment.
Return values
void

Definition at line 611 of file ODComboBox.cpp.

◆ GetODItemHorzAlignment()

CHorzAlignment BIS_WTL_CONTROLS::CODComboBox::GetODItemHorzAlignment ( int  index) const

Default: haLeft.

Returns the current horizontal text alignment of a selected combobox item.

Parameters
indexZero-based item index.
Return values
CHorzAlignmentThe current horizontal alignment.

Definition at line 592 of file ODComboBox.cpp.

◆ SetODItemVertAlignment()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemVertAlignment ( int  index,
CVertAlignment  value 
)

Modify the vertical text aligment of the selected combobox item.

Parameters
indexThe zero-based index of the item to modify.
valueThe new vertical alignment.
Return values
void

Definition at line 647 of file ODComboBox.cpp.

◆ GetODItemVertAlignment()

CVertAlignment BIS_WTL_CONTROLS::CODComboBox::GetODItemVertAlignment ( int  index) const

DefaultL: vaMiddle.

Returns the current vertical text alignment of the sleected combobox item.

Parameters
indexZero-based item index.
Return values
CVertAlignmentThe current vertical alignment.

Definition at line 628 of file ODComboBox.cpp.

◆ SetODItemWordWrap()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemWordWrap ( int  index,
bool  wrap 
)

Modify the WordWrap state of the selected combobox item.

If the WordWrap state of a combobox item is /c true, the DT_WORDBREAK flag is applied when text is drawn. If WordWrap is /c false. the DT_SINGLELINE flag is applied. See the MSDN documentation for the DrawText API for more information.

Parameters
indexThe zero-based index of the item to modify.
wrapThe new bool state.
Return values
void

Definition at line 685 of file ODComboBox.cpp.

◆ GetODItemWordWrap()

bool BIS_WTL_CONTROLS::CODComboBox::GetODItemWordWrap ( int  index) const

Default: false.

Returns the current WordWrap state of the selected combobox item.

Parameters
indexZero-based item index.
Return values
boolThe current WordWrap state.

Definition at line 664 of file ODComboBox.cpp.

◆ SetODItemUseEllipsis()

void BIS_WTL_CONTROLS::CODComboBox::SetODItemUseEllipsis ( int  index,
bool  ellipsis 
)

Modify the UseEllipsis state of the selected combobox item.

if the UseEllipsis state of a combobox item is /c true, the DT_ENDELLIPSIS flag is applied when text is drawn. See the MSDN documentation for the DrawText API for more information.

Parameters
indexThe zero-based index of the item to modify.
ellipsisThe new bool state.
Return values
void

Definition at line 722 of file ODComboBox.cpp.

◆ GetODItemUseEllipsis()

bool BIS_WTL_CONTROLS::CODComboBox::GetODItemUseEllipsis ( int  index) const

Default: true.

Returns the current UseEllipsis state of the selected combobox item.

Parameters
indexZero-based item index.
Return values
boolThe current UseEllipsis state.

Definition at line 702 of file ODComboBox.cpp.


The documentation for this class was generated from the following files: